home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q0429.dms / q0429.adf / raypaint / glgraphics.c next >
C/C++ Source or Header  |  1991-08-08  |  3KB  |  151 lines

  1. /*
  2.  * glgraphics.c
  3.  *
  4.  * Copyright (C) 1989, 1991 Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  * 
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: glgraphics.c,v 4.0 91/07/17 17:36:39 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    glgraphics.c,v $
  19.  * Revision 4.0  91/07/17  17:36:39  kolb
  20.  * Initial version.
  21.  * 
  22.  * 
  23.  */
  24.  
  25. #include <gl.h>
  26. #include <device.h>
  27.  
  28. #define CPACK(x)    cpack(((((x)[2] << 8) | (x)[1]) << 8) | x[0])
  29.  
  30. GraphicsInit(xsize, ysize, name)
  31. int xsize, ysize;
  32. char *name;
  33. {
  34. #ifndef _IBMR2
  35.     foreground();
  36. #endif
  37.     prefsize(xsize, ysize);
  38.     winopen(name);
  39.     ortho2(-0.5, (float)xsize -0.5, -0.5, (float)ysize - 0.5);
  40.     viewport(0, xsize -1, 0, ysize -1);
  41.     color(BLACK);
  42.     clear();
  43.     RGBmode();
  44.     gconfig();
  45.     unqdevice(INPUTCHANGE);
  46.     qdevice(LEFTMOUSE);  /* Pop a square on request */
  47.     qdevice(MIDDLEMOUSE);
  48.     qdevice(RIGHTMOUSE);
  49.     qdevice(REDRAW);
  50. }
  51.  
  52. /*
  53.  * Draw the pixel at (xp, yp) in the color given by the rgb-triple,
  54.  * 0 indicating 0 intensity, 255 max intensity.
  55.  */
  56. GraphicsDrawPixel(xp, yp, color)
  57. int xp, yp;
  58. unsigned char color[3];
  59. {
  60.     unsigned long int pix;
  61.  
  62.     pix = (((color[2] << 8) | color[1]) << 8) | color[0];
  63.     lrectwrite(xp, yp, xp, yp, &pix);
  64. }
  65.  
  66. /*
  67.  * Draw the rectangle with lower left corner (xp, yp) and upper right
  68.  * corner (xp+ys, yp+ys).  The colors of the l-l, l-r, u-r, and u-l
  69.  * corners are given as arrays of unsigned chars as above.
  70.  */
  71. GraphicsDrawRectangle(xp, yp, xs, ys, ll, lr, ur, ul)
  72. int xp, yp, xs, ys;
  73. unsigned char ll[3], lr[3], ur[3], ul[3];
  74. {
  75.     int   p[2];
  76.  
  77. #if defined(_IBMR2) && !defined(SHARED_EDGES)
  78.     /*
  79.      * RS6000 doesn't seem to draw lower and left edges
  80.      * of rectangles correctly.
  81.      */
  82.     xp--; yp--;
  83.     xs++; ys++;
  84. #endif
  85.     bgnpolygon();
  86.  
  87.     p[0] = xp; p[1] = yp;
  88.     CPACK(ll);
  89.     v2i(p);
  90.  
  91.     p[0] += xs;
  92.     CPACK(lr);
  93.     v2i(p);
  94.  
  95.     p[1] += ys;
  96.     CPACK(ur);
  97.     v2i(p);
  98.     
  99.     p[0] = xp;
  100.     CPACK(ul);
  101.     v2i(p);
  102.  
  103.     endpolygon();
  104. }
  105.  
  106. GraphicsLeftMouseEvent()
  107. {
  108.     /*
  109.      * Return TRUE if left mouse button is down.
  110.      */
  111.     return getbutton(LEFTMOUSE);
  112. }
  113.  
  114. GraphicsMiddleMouseEvent()
  115. {
  116.     return getbutton(MIDDLEMOUSE);
  117. }
  118.  
  119. GraphicsRightMouseEvent()
  120. {
  121.     return getbutton(RIGHTMOUSE);
  122. }
  123.  
  124. /*
  125.  * Return position of mouse in unnormalized screen coordinates.
  126.  */
  127. GraphicsGetMousePos(x, y)
  128. int *x, *y;
  129. {
  130.     int xo, yo;
  131.  
  132.     getorigin(&xo, &yo);
  133.     *x = getvaluator( MOUSEX ) - xo;
  134.     *y = getvaluator( MOUSEY ) - yo;
  135. }
  136.  
  137. GraphicsRedraw()
  138. {
  139.     Device dev;
  140.     short val;
  141.  
  142.     while (qtest()) {
  143.         dev = qread(&val);
  144.         if (dev == REDRAW) {
  145.             reshapeviewport();
  146.             return TRUE;
  147.         }
  148.     }
  149.     return FALSE;
  150. }
  151.